<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Activity extends Model
{
    /**
     * 结束报名
     */
    public function endRegister(){
        $this->setAttribute('status', 9);
        $this->save();
    }

    /**
     * 统计报名人数
     *
     * @return mixed
     */
    public function countPartners(){
        return Registration::where('activity_id', $this->id)->count();
    }

    /**
     * 更新剩余名额
     */
    public function updateRemainingNo(){
        $remaining_no = $this->max_no - $this->countPartners();
        $this->setAttribute('remaining_no', $remaining_no);
        $this->save();
    }
}
